package xyz.erupt.flow.data.mapper;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import xyz.erupt.flow.bean.entity.OaWorkFlowDefinition;
import xyz.erupt.flow.bean.entity.OaWorkFlowGroup;
import xyz.erupt.flow.data.dto.DTO_OaWorkFlowDefinition;
import xyz.erupt.flow.data.vo.VO_OaWorkFlowDefinition;

import java.util.List;

/**
 * @author PP
 * @version 1.0
 * @project flow
 * @description
 * @date 2025/1/8 11:03:30
 */
@Mapper
public interface OaWorkFlowDefinitionMapper {
    OaWorkFlowDefinitionMapper INSTANCE = Mappers.getMapper(OaWorkFlowDefinitionMapper.class);

    @Mappings({
            @Mapping(source = "workFlowGroup.groupId",target = "workFlowGroup")
    })
    DTO_OaWorkFlowDefinition toDto(OaWorkFlowDefinition o);

    @Mappings({
            @Mapping(target = "workFlowGroup",expression = "java(toOaWorkFlowGroup(dto.getWorkFlowGroup()))")
    })
    OaWorkFlowDefinition dtoTo(DTO_OaWorkFlowDefinition dto);

    @Mappings({
            @Mapping(source = "workFlowGroup.groupId",target = "workFlowGroupId"),
            @Mapping(source = "workFlowGroup.groupName",target = "workFlowGroupName")
    })
    VO_OaWorkFlowDefinition toVo(OaWorkFlowDefinition o);

    List<VO_OaWorkFlowDefinition> toVo(List<OaWorkFlowDefinition> o);

    default OaWorkFlowGroup toOaWorkFlowGroup(Long workFlowGroup) {
        if (workFlowGroup == null || workFlowGroup <= 0) {
            return null;
        }else {
            return OaWorkFlowGroup.builder().groupId(workFlowGroup).build();
        }
    }
}
